package cn.rxmind.dlicense.server.api;

import cn.rxmind.dlicense.core.exception.DLicenseErrEnum;
import cn.rxmind.dlicense.core.exception.DLicenseException;
import cn.rxmind.dlicense.server.base.BaseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 异常拦截器
 *
 * @author renxin
 * @email renxinzhiliangzhi@163.com
 * @date 2021/4/20 1:45 下午
 */
@Slf4j
@RestControllerAdvice(basePackageClasses = {LicenseController.class})
public class ApiExceptionHandler {

    @ExceptionHandler(value = DLicenseException.class)
    public BaseResult utryLicenseException(DLicenseException e){
        log.error(e.getMessage());
        return BaseResult.buildWithUtryLicenseException(e);
    }

    @ExceptionHandler(value = Exception.class)
    public BaseResult otherException(Exception e){
        e.printStackTrace();
        return BaseResult.build(DLicenseErrEnum.SYSTEM_ERROR);
    }

}
